<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ctrl_afficherForm
 *
 * @author Rolland
 */
class ctrl_afficherForm {
    function __construct() {
        if(isset($_POST['type'], $_POST['entrepot'])){
            $ins = new BDDEntreeStock(0, date("Y-m-d"), $_POST['societe'], $_POST['entrepot'], NULL);
            $ins->entreeArticle($_POST['type'], $_POST['entrepot'], $_POST['societe']);
            $entr = new BDDUser();
            $aff = new vMain();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $aff->afficher($lesE);
            
        }
        elseif(isset($_GET['id']) && $_GET['do'] == "sortir"){
            $b = BDDEntreeStock::byArticleId($_GET['id']);
            BDDSortieStock::sortieArticle($_GET['id'], $b["entrepot"]->getId(), $b["societe"]->getId());
            $entr = new BDDUser();
            $aff = new vMain();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $aff->afficher($lesE);
        }
        elseif(isset($_POST['entrepot'])){
            $b = BDDEntreeStock::byArticleId($_POST['id']);
            BDDEntreeStock::moveArticle($_POST['id'], $b["entrepot"]->getId(), $_POST['entrepot'], $b["societe"]->getId());
            $entr = new BDDUser();
            $aff = new vMain();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $aff->afficher($lesE);
        }
        elseif(!isset($_POST['type'], $_POST['entrepot']) && $_GET["do"] == "ajouter"){
            $entr = new BDDUser();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $ajout = new vModif();
            $ajout->afficher($lesE);
        }
        elseif(!isset($_POST['entrepot']) && $_GET["do"] == "modif"){
            $entr = new BDDUser();
            $i = 0;
            foreach($entr->getEntrepots() as $s){
                $lesE[$i] = array('site'=>$s->getSite(), 'id'=>$s->getId());
                $i++;
            }
            $ajout = new vModif();
            $ajout->afficher($lesE, $_GET['id']);
        }
    }
}

?>
